﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    /// <summary>
    ///  create by Guoph at 2017.3.28
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ShopsBrowse_Bll<T> where T : class
    {
        /// <summary>
        /// 获取商铺信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic Model, int index, out int TotalCount, string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = " ( StreetOfficeID = " + Dtid + " or Dt_ParentId = " + Dtid + " )";
            }
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.Bd_Name != null)
            {
                sqlSurch += " and " + " Bd_Name like '%" + Model.Bd_Name + "%'  ";
            }
            if (Model.Uim_Name != null)
            {
                sqlSurch += " and " + " Uim_Name like '%" + Model.Uim_Name + "%'  ";
            }

            if (Model.stateTime != null && Model.endTime == null)
            {
                int date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.stateTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime = " + date + " ";
            }
            if (Model.stateTime == null && Model.endTime != null)
            {
                int date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.endTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime = " + date + "  ";
            }
            if (Model.stateTime != null && Model.endTime != null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse(Model.stateTime.ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse(Model.endTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime >= " + state + "  and Hs_CreateTime<=" + end + " ";
            }

            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.NatPer_IDNumber != null)
            {
                sqlSurch += " and " + " NatPer_IDNumber = '" + Model.NatPer_IDNumber + "'  ";
            }
            if (Model.NatPer_Phone != null)
            {
                sqlSurch += " and " + " NatPer_Phone = '" + Model.NatPer_Phone + "'  ";
            }          
            if (Model.HsHousUse != null)
            {
                sqlSurch += " and " + " HsHousUse = '" + Model.HsHousUse + "'  ";
            }
            return PagerHelp<T>.GetPagerList(index, "V_ShopsBrowse", "Community", out TotalCount, sqlSurch);
        }

     
        /// <summary>
        /// 商铺浏览信息导出
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public static List<T> GetShopsBrowseList(dynamic Model, string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = " ( StreetOfficeID = " + Dtid + " or Dt_ParentId = " + Dtid + " )";
            }
            if (Model.StreetOffice != null || Model.StreetOffice !="")
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.Bd_Name != null)
            {
                sqlSurch += " and " + " Bd_Name like '%" + Model.Bd_Name + "%'  ";
            }
            if (Model.Uim_Name != null)
            {
                sqlSurch += " and " + " Uim_Name like '%" + Model.Uim_Name + "%'  ";
            }

            if (Model.stateTime != null && Model.endTime == null)
            {
                int date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.stateTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime = " + date + " ";
            }
            if (Model.stateTime == null && Model.endTime != null)
            {
                int date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.endTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime = " + date + "  ";
            }
            if (Model.stateTime != null && Model.endTime != null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse(Model.stateTime.ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse(Model.endTime.ToString()));
                sqlSurch += " and " + " Hs_CreateTime >= " + state + "  and Hs_CreateTime<=" + end + " ";
            }

            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.NatPer_IDNumber != null)
            {
                sqlSurch += " and " + " NatPer_IDNumber = '" + Model.NatPer_IDNumber + "'  ";
            }
            if (Model.NatPer_Phone != null)
            {
                sqlSurch += " and " + " NatPer_Phone = '" + Model.NatPer_Phone + "'  ";
            }
            if (Model.HsHousUse != null)
            {
                sqlSurch += " and " + " HsHousUse = '" + Model.HsHousUse + "'  ";
            }
            return ShopsBrowse_DAL<T>.SelectShopsBrowseList(sqlSurch);
        }
    }
}
